package org.framework.edge.builder.application.impl;

import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.framework.edge.builder.application.DockerBuilderApplication;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.framework.edge.builder.domain.model.docker.builder.DockerBuilder;
import org.framework.edge.builder.application.command.docker.builder.DockerBuilderRemoveCommand;
import org.framework.edge.builder.application.command.docker.builder.DockerBuilderStoryCommand;
import org.framework.edge.builder.application.command.docker.builder.DockerBuilderUpdateCommand;
import org.framework.edge.builder.application.command.docker.builder.DockerBuilderQueryListCommand;
import org.framework.edge.builder.application.command.docker.builder.DockerBuilderQueryOneCommand;
import org.framework.edge.builder.application.assembler.DockerBuilderDTOAssembler;
import org.framework.edge.builder.application.dto.DockerBuilderDTO;
import java.util.stream.Collectors;
import jakarta.annotation.Resource;
import org.framework.edge.builder.domain.model.docker.builder.DockerBuilderRepository;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.framework.edge.builder.application.command.docker.builder.DockerBuilderExcelExport;
import org.framework.edge.builder.application.command.docker.builder.DockerBuilderExcelImport;
/**
 * describe docker 打包 
 *
 * @author Jia wei Wu
 * @date 2025/07/08 06:06 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class DockerBuilderApplicationImpl implements DockerBuilderApplication {

    @Resource
    DockerBuilderRepository dockerBuilderRepository;
    /**
     * describe 新增docker 打包
     *
     * @param dockerBuilderStoryCommand 新增docker 打包     
     * @return {@link Result<DockerBuilder>} docker 打包新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<DockerBuilder> story(DockerBuilderStoryCommand dockerBuilderStoryCommand) {
        DockerBuilder dockerBuilder = DockerBuilderDTOAssembler.INSTANCE.toDockerBuilder(dockerBuilderStoryCommand);
        return dockerBuilderRepository.story(dockerBuilder);
    }
    /**
     * describe 批量新增docker 打包
     *
     * @param dockerBuilderStoryCommandList 批量新增docker 打包     
     * @return {@link Result<List<DockerBuilder>>} docker 打包新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<List<DockerBuilder>> batchStory(List<DockerBuilderStoryCommand> dockerBuilderStoryCommandList) {
        List<DockerBuilder> dockerBuilderList = dockerBuilderStoryCommandList.stream().map( DockerBuilderDTOAssembler.INSTANCE::toDockerBuilder).collect(Collectors.toList());
        return dockerBuilderRepository.batchStory(dockerBuilderList);
    }
    /**
     * describe 更新docker 打包
     *
     * @param dockerBuilderUpdateCommand 更新docker 打包     
     * @return {@link Result<DockerBuilder>} docker 打包领域对象     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<DockerBuilder> updateOne(DockerBuilderUpdateCommand dockerBuilderUpdateCommand) {
        DockerBuilder dockerBuilder = DockerBuilderDTOAssembler.INSTANCE.toDockerBuilder(dockerBuilderUpdateCommand);
        return dockerBuilderRepository.story(dockerBuilder);
    }

    /**
     * describe 查询单个docker 打包
     *
     * @param dockerBuilderQueryOneCommand 查询单个docker 打包     
     * @return {@link Result<DockerBuilderDTO>} docker 打包DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<DockerBuilderDTO> findOne(DockerBuilderQueryOneCommand dockerBuilderQueryOneCommand) {
        DockerBuilder dockerBuilder = DockerBuilderDTOAssembler.INSTANCE.toDockerBuilder(dockerBuilderQueryOneCommand);
        return dockerBuilderRepository.findOne(dockerBuilder).convert(DockerBuilderDTOAssembler.INSTANCE::fromDockerBuilder);
    }

    /**
     * describe 查询多个docker 打包
     *
     * @param dockerBuilderQueryListCommand 查询多个docker 打包     
     * @return {@link Result<List<DockerBuilderDTO>>} docker 打包DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<List<DockerBuilderDTO>> findList(DockerBuilderQueryListCommand dockerBuilderQueryListCommand) {
        DockerBuilder dockerBuilder = DockerBuilderDTOAssembler.INSTANCE.toDockerBuilder(dockerBuilderQueryListCommand);
        return dockerBuilderRepository.findList(dockerBuilder)        .convert(dockerBuilders -> dockerBuilders.stream().map(DockerBuilderDTOAssembler.INSTANCE::fromDockerBuilder).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个docker 打包
     *
     * @param dockerBuilderQueryListCommand 分页查询多个docker 打包     
     * @return {@link Result<LazyPage<DockerBuilderDTO>>} 分页docker 打包DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<LazyPage<DockerBuilderDTO>> findPage(int size,int current,DockerBuilderQueryListCommand dockerBuilderQueryListCommand) {
        DockerBuilder dockerBuilder = DockerBuilderDTOAssembler.INSTANCE.toDockerBuilder(dockerBuilderQueryListCommand);
        return dockerBuilderRepository.findPage(size,current,dockerBuilder)        .convert(page -> page.convert(DockerBuilderDTOAssembler.INSTANCE::fromDockerBuilder))            ;
    }

    /**
     * describe 删除docker 打包
     *
     * @param dockerBuilderRemoveCommand 删除docker 打包     
     * @return {@link Result<DockerBuilder>} docker 打包     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<DockerBuilder> remove(DockerBuilderRemoveCommand dockerBuilderRemoveCommand) {
     DockerBuilder dockerBuilder = DockerBuilderDTOAssembler.INSTANCE.toDockerBuilder(dockerBuilderRemoveCommand);
     return dockerBuilderRepository.remove(dockerBuilder);
    }

    /**
     * describe 导出docker 打包
     *
     * @param dockerBuilderQueryListCommand 导出docker 打包     
     * @return {@link List<DockerBuilderExcelExport>} docker 打包     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public List<DockerBuilderExcelExport> exportExcel(DockerBuilderQueryListCommand dockerBuilderQueryListCommand) {
     DockerBuilder dockerBuilder = DockerBuilderDTOAssembler.INSTANCE.toDockerBuilder(dockerBuilderQueryListCommand);
        return dockerBuilderRepository.findList(dockerBuilder)        .applyOther(dockerBuilders -> dockerBuilders.stream().map(DockerBuilderDTOAssembler.INSTANCE::fromDockerBuilderToExcelExport).collect(Collectors.toList())) ;
    }

    /**
     * describe 导入docker 打包
     *
     * @param dockerBuilderExcelImportList 导入docker 打包     
     * @return {@link Result<DockerBuilderExcelImport>} docker 打包     
     
     * @author Jia wei Wu
     * @date 2025/07/08 06:06 晚上
     **/

    @Override
    public Result<List<DockerBuilderExcelImport>> importExcel(List<DockerBuilderExcelImport> dockerBuilderExcelImportList) {
        List<DockerBuilder> dockerBuilderList = dockerBuilderExcelImportList.stream().map( DockerBuilderDTOAssembler.INSTANCE::toDockerBuilder).collect(Collectors.toList());
        dockerBuilderRepository.batchStory(dockerBuilderList);
        return ResultFactory.successOf(dockerBuilderExcelImportList);
    }
}